<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "gky_qyh_menu".
 *
 * @property integer $id
 * @property integer $app_id
 * @property integer $pid
 * @property string $name
 * @property integer $type
 * @property string $key
 * @property string $url
 * @property integer $sort
 * @property integer $isSet
 */
class GkyQyhMenu extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'gky_qyh_menu';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['app_id', 'pid', 'name', 'type', 'sort', 'isSet'], 'required'],
            [['app_id', 'pid', 'type', 'sort', 'isSet'], 'integer'],
            [['name', 'key', 'url'], 'string', 'max' => 255],
        ];
    }

    public function getApp(){

        return $this->hasOne(GkyQyhApp::className(),['id'=>'app_id']);
    }

    public function getParent(){

        return $this->hasOne(GkyQyhMenu::className(),['id'=>'pid']);
    }

    public function getSubs(){

        return $this->hasMany(GkyQyhMenu::className(),['pid'=>'id'])->orderBy(['sort'=>SORT_ASC]);
    }

    public function getMenuType(){

        return $this->hasOne(GkyWeMenuType::className(),['id'=>'type']);
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'app_id' => 'App ID',
            'pid' => 'Pid',
            'name' => 'Name',
            'type' => 'Type',
            'key' => 'Key',
            'url' => 'Url',
            'sort' => 'Sort',
            'isSet' => 'Is Set',
        ];
    }
}
